<?php
/**
 *
 * User: lang@vip.deyi.com
 * Date: 2017/4/20
 * Time: 15:59
 */

namespace Apps\Common\Service;


use Apps\Common\Constant\CacheKeyConstant;
use Apps\Common\Constant\CacheTimeoutConstant;
use Apps\Common\Model\BaseModel;
use Deyi\Functions\CacheFunction;

class BaseService extends BaseModel
{
    public function initialize()
    {
        parent::initialize();
    }

    public function getMethodCache($extraKey = '')
    {
        $calledFunc = debug_backtrace()[1]['function'];
        $cacheKey = CacheFunction::generateKey(CacheKeyConstant::SERVICE_METHOD_CACHE_KEY, get_called_class(), $calledFunc, $extraKey);

        return static::$_memcached->get($cacheKey);
    }

    public function setMethodCache($data, $expire = CacheTimeoutConstant::LOCAL_CACHE, $extraKey = '')
    {
        $calledFunc = debug_backtrace()[1]['function'];
        $cacheKey = CacheFunction::generateKey(CacheKeyConstant::SERVICE_METHOD_CACHE_KEY, get_called_class(), $calledFunc, $extraKey);

        return static::$_memcached->set($cacheKey, $data, $expire);
    }

}